package com.network.retrofit_rx.Api;

import android.support.annotation.Keep;
import android.text.TextUtils;

import com.alibaba.fastjson.annotation.JSONField;

/**
 * 回调信息统一封装类
 *
 * @author WZG
 * @date 2016/7/16
 * "code": "200",
 * "msg": "",
 * "time": "46毫秒",
 */
@Keep
public class BaseResultEntity {
    /**
     * 判断标
     */
    private String code;

    /**
     * 提示信息
     */
    private String message;
    private String time;
    /**
     * 显示数据（用户需要关心的数据）
     * <p>
     */
    @JSONField(alternateNames = {"list", "data", "userinf", "item", "items","UserInf","inf","Inf","SJList","orderdetail"})
    private String data;

    public String getDescription() {
        if (!TextUtils.isEmpty(message)) {
            return message;
        }

        switch (code) {
            case "400":
                message = "请求信息不完整";
                break;
            case "422":
                message = "请求数据不合法";
                break;
            case "404":
                message = "资源不存在";
                break;
            case "405":
                break;
            case "409":
                break;
            case "401":
                message = "用户不存在";
                break;
            case "403":
                message = "权限不足";
                break;
            case "520":
                message = "token验证有误";
                break;
            default:
                break;
        }
        return message;
    }

    public void setDescription(String msg) {
        this.message = msg;
    }

    public String getData() {
        return data;
    }

    public void setData(String data) {
        this.data = data;
    }

    public boolean isSuccess() {
        return code.equals("200");
    }

    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    public String getMsg() {
        return message;
    }

    public void setMsg(String msg) {
        this.message = msg;
    }

    public String getTime() {
        return time;
    }

    public void setTime(String time) {
        this.time = time;
    }
}
